import { request } from '@/service/request';

/** 报表设计API */

/**
 * 查询报表设计列表
 */
export function fetchReportList(params?: Api.DataPlatform.ReportSearchParams) {
  return request<Api.DataPlatform.ReportList>({
    url: '/dataplatform/report/list',
    method: 'get',
    params
  });
}

/**
 * 查询报表设计详情
 */
export function fetchReportDetail(id: number) {
  return request<Api.DataPlatform.ReportDetail>({
    url: `/dataplatform/report/${id}`,
    method: 'get'
  });
}

/**
 * 新增报表设计
 */
export function addReport(data: Api.DataPlatform.ReportEdit) {
  return request({
    url: '/dataplatform/report',
    method: 'post',
    data
  });
}

/**
 * 修改报表设计
 */
export function updateReport(data: Api.DataPlatform.ReportEdit) {
  return request({
    url: '/dataplatform/report',
    method: 'put',
    data
  });
}

/**
 * 删除报表设计
 */
export function deleteReport(ids: number[]) {
  return request({
    url: `/dataplatform/report/${ids.join(',')}`,
    method: 'delete'
  });
}

/**
 * 获取图表数据
 */
export function fetchChartData(reportId: number, chartId: string, filters?: Record<string, any>) {
  return request<Api.DataPlatform.ChartData>({
    url: `/dataplatform/report/${reportId}/chart/${chartId}/data`,
    method: 'post',
    data: filters || {}
  });
}

/**
 * 导出报表
 */
export function exportReport(reportId: number, format: string = 'PDF') {
  return request<Blob>({
    url: `/dataplatform/report/${reportId}/export`,
    method: 'get',
    params: { format },
    responseType: 'blob'
  });
}

/**
 * 发布报表
 */
export function publishReport(id: number) {
  return request({
    url: `/dataplatform/report/${id}/publish`,
    method: 'post'
  });
}

/**
 * 下线报表
 */
export function offlineReport(id: number) {
  return request({
    url: `/dataplatform/report/${id}/offline`,
    method: 'post'
  });
}
